<?php

namespace Modules\User\Http\Controllers\Client\V1;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;

use Modules\User\Entities\UserGroup;

use Auth;
use Validator;
use ThrowException;

class UserGroupController extends Controller
{
    // 检测
    public function check(Request $req)
    {
        $rule = [
            'id' => ['required'],
        ];
        Validator::make($req->all(), $rule)->fails() && ThrowException::BadRequest(); 

        $user = Auth::requireLoginUser();

        $userGroup = UserGroup::getEntity([
            'id' => $req->id
        ]);

        list($isPassed, $options) = $userGroup->checkRule($user);

        return [
            'is_passed' => $isPassed,
            'options' => $options
        ];
    }
}
